#ifndef __MIN_STACK__
#define __MIN_STACK__
#include<iostream>
#include<vector>
using namespace std;

class MinStack {
public:
    /** initialize your data structure here. */
    MinStack() {}
    
    void push(int x) {
        if(stack.size() == 0){
            min_m.push_back(x);
            stack.push_back(x);
        }
        else{
            if(x <= *(min_m.end() - 1))
                min_m.push_back(x);
            stack.push_back(x);
        }
    }
    
    void pop() {
        if(*(stack.end() - 1) == *(min_m.end() - 1))
            min_m.pop_back();
        stack.pop_back();
    }
    
    int top() {
        return *(stack.end() - 1);
    }
    
    int min() {
        return *(min_m.end() - 1);
    }
    vector<int> min_m;
    vector<int> stack;
};


#endif